/*
 * Package il.ac.biu.cs.grossmm.api.flow
 * File ConverterProxyBase.java
 * 
 * This is a part of presence service framework API. 
 * See javadoc for more information.
 *  
 * Copyright (C) 2006 Grossmann Mark
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package il.ac.biu.cs.grossmm.api.flow;

import il.ac.biu.cs.grossmm.api.OperationFailedException;
import il.ac.biu.cs.grossmm.api.data.Root;

/**
 * Provides base framework for implementation of converter proxies both for
 * conditional and unconditional converters. This class is abstract and only
 * <tt>convert</tt> method should be implemented by the subclass.
 */
public abstract class ConverterProxyBase<Nsrc, Ndst> implements
	ConverterProxy<Nsrc, Ndst> {

	protected Root<Nsrc> srcRoot;

	protected Root<Ndst> dstRoot;

	/**
	 * Should be called in <tt>createProxy</tt> method of a <tt>Converter</tt>
	 * or <tt>ConditionalConverter</tt> which makes use of this class.
	 * 
	 * @param srcRoot
	 *            source data tree root
	 * @param dstRoot
	 *            desination data tree root
	 * @param srcInspector
	 *            source node inspector
	 * @param dstManipulator
	 *            destination node manipulator
	 * @throws OperationFailedException
	 */
	public ConverterProxyBase(Root<Nsrc> srcRoot, Root<Ndst> dstRoot,
		NodeInspector srcInspector, NodeManipulator dstManipulator)
		throws OperationFailedException
	{
		this.srcRoot = srcRoot;
		this.dstRoot = dstRoot;
		convert(srcInspector, dstManipulator);
	}

	public void convert(NodeEventInspector srcInspector,
		NodeManipulator dstManipulator) throws OperationFailedException
	{
		convert((NodeInspector) srcInspector, dstManipulator);
	}

	/**
	 * Converts source tree to destination tree using given inspector and
	 * manipulator. The source tree is <tt>srcRoot</tt> field of this class
	 * and destination tree is <tt>dstRoot</tt> field of this class.
	 * 
	 * @param srcInspector
	 *            node inspector to inspect source data tree
	 * @param dstManipulator
	 *            node manipulator to update the destination data tree
	 * @throws OperationFailedException
	 */
	protected abstract void convert(NodeInspector srcInspector,
		NodeManipulator dstManipulator) throws OperationFailedException;

	public void release()
	{
	}
}
